// pages/couponList/couponList.js
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    _token: '',
    imgpath: '',

    couponobj:'',
    couponlist:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var _key = wx.getStorageSync("token");
    var _imgpath = app.globalData.imgsPath;
    that.setData({
      _token: _key,
      imgpath: _imgpath
    })
    // wx.showLoading({
    //   title: '数据加载中',
    // })
    that.getcouponList();
  },
  //获取订单列表
  getcouponList: function() {
    var that = this;
    var _key = that.data._token;
    wx.request({
      url: app.globalData.httpsPath + '/user/coupon/index',
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      data: {
        token: _key,
      },
      //请求后台数据成功  
      success: function (res) {
        var _couponjson = res.data.data;
        var _couponlist = res.data.data.data;
        console.info(_couponlist);
        that.setData({
          couponobj: _couponjson,
          couponlist: _couponlist
        })
        // 隐藏加载框
        wx.hideLoading();
      }
    })
  },
  //使用优惠券
  useCoupon:function(e){
    var _id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../confirmOrder/confirmOrder?couponId=' + _id,
    })
  },
  
})